package com.bz.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bz.common.HttpUtil;
// import com.bz.service.IAimodelService;

@RestController
@RequestMapping(value = "/api/mes")
public class MesController {

    @Value("${mes.url.workTaskOut}")
    private String workTaskOut;
    @Value("${mes.url.palletsTraceIn}")
    private String palletsTraceIn;
    @Value("${mes.url.workTaskIn}")
    private String workTaskIn;
    @Value("${mes.url.dataAcquireIn}")
    private String dataAcquireIn;
    @Value("${mes.url.alarmInfoIn}")
    private String alarmInfoIn;
    @Value("${mes.url.workTaskResourceReadyOut}")
    private String workTaskResourceReadyOut;
    @Value("${mes.url.kpiDataOut}")
    private String kpiDataOut;
    @Value("${mes.url.storeListIn}")
    private String storeListIn;
    @Value("${mes.url.type4ListIn}")
    private String type4ListIn;
    @Value("${mes.url.upProduct4Agv}")
    private String upProduct4Agv;
    @Value("${mes.url.downProduct4Agv}")
    private String downProduct4Agv;

    /**
     * 2.2.1. 工单工艺数据下发（调用）
     * 
     * @param deviceId
     * @param orderSendBeginTime
     * @param orderSendEndTime
     * @return
     */
    @GetMapping(value = "/work-task-out")
    public String workTaskOut(String deviceId, String orderSendBeginTime, String orderSendEndTime) {
        String url = workTaskOut + "?deviceId=" + deviceId + "&orderSendBeginTime=" + orderSendBeginTime + "&orderSendEndTime=" + orderSendEndTime;
        return HttpUtil.doGet(url);
    }

    /**
     * 2.2.3. 托盘过程数据上传（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/pallets-trace-in")
    public String palletsTraceIn(@RequestBody String json) {
        String url = palletsTraceIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.4. 工单完工数据上传（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/work-task-in")
    public String workTaskIn(@RequestBody String json) {
        String url = workTaskIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.5. 数据采集接口（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/data-acquire-in")
    public String dataAcquireIn(@RequestBody String json) {
        String url = dataAcquireIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.6. 设备报警接口（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/alarm-info-in")
    public String alarmInfoIn(@RequestBody String json) {
        String url = alarmInfoIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.9. 资源齐套信息接口（调用，仅做测试）
     * 
     * @param json
     * @return
     */
    @GetMapping(value = "/work-task-resource-ready-out")
    public String workTaskResourceReadyOut(String deviceId, String workId) {
        String url = workTaskResourceReadyOut + "?deviceId=" + deviceId + "&workId=" + workId;
        return HttpUtil.doGet(url);
    }

    /**
     * 2.2.10. 统计分析指标（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/kpi-data-out")
    public String kpiDataOut(@RequestBody String json) {
        String url = kpiDataOut;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.11. 仓库列表上报（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/store-list-in")
    public String storeListIn(@RequestBody String json) {
        String url = storeListIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.12. 托盘列表上报（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/type4-list-in")
    public String type4ListIn(@RequestBody String json) {
        String url = type4ListIn;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.17. 请求来料（调用）
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/up-product-4Agv")
    public String upProduct4Agv(@RequestBody String json) {
        String url = upProduct4Agv;
        return HttpUtil.doPOST(url, json, null);
    }

    /**
     * 2.2.18. 请求卸料（调用） 产品加工完成带走产品
     * 
     * @param json
     * @return
     */
    @PostMapping(value = "/down-product-4Agv")
    public String downProduct4Agv(@RequestBody String json) {
        String url = downProduct4Agv;
        return HttpUtil.doPOST(url, json, null);
    }
}
